package org.myy.learn.hot.finish.滑动窗口;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

public class 无重复字符的最长字串 {
    public static int lengthOfLongestSubstring(String s) {
        char[] strs = s.toCharArray();
        int longest = 0;
        Set<Character> set = new HashSet<>();
        //ToDo  l和r如何滑动?
        for (int l = 0, r = 0; r < s.length(); r++){
            char c = strs[r];
            while (set.contains(c)){
                set.remove(strs[l]);
                l++;
            }
            set.add(c);
            longest = Math.max(longest, r - l + 1);
        }
        return longest;
    }

    public static void main(String[] args) {
        String s = "pwwkew";
        int longest = lengthOfLongestSubstring(s);
        System.out.println(longest);
    }
}
